const obj = {
  foo: "value1",
  bar: "value2",
};

// Object.values
console.log(Object.values(obj));

// Object.keys
console.log(Object.keys(obj));

// Object.entries: 以数组的形式返回所有的键值对
console.log(Object.entries(obj));
for (const [key, value] of Object.entries(obj)) {
  console.log(key, value);
}

// obj 转 map
console.log(new Map(Object.entries(obj)));

// Object.getOwnPropertyDescriptors: 获取对象的完整描述信息
const p1 = {
  firstName: "Lei",
  lastName: "wang",
  get fullName() {
    return this.firstName + " " + this.lastName;
  },
};
console.log(p1.fullName);
// 这里赋值把fullName当作普通属性赋值了
/* let p2 = Object.assign({}, p1);
p2.firstName = "zce";
console.log(p2.fullName); */

const descriptors = Object.getOwnPropertyDescriptors(p1);
const p2 = Object.defineProperties({}, descriptors);
p2.firstName = "zce";
console.log(p2.fullName);

// padStart, padEnd
const books = {
  html: 5,
  css: 16,
  javascript: 128,
};

for (const [name, count] of Object.entries(books)) {
  console.log(`${name.padEnd(16, "-")}|${count.toString().padStart(3, "0")}`);
}
